package com.jl.jlapp.mvp.fragment;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.CliassifyAdapter;
import com.jl.jlapp.adapter.CliassifyDetailsAdapter;
import com.jl.jlapp.eneity.AdvertisementByIdModel;
import com.jl.jlapp.eneity.ClassificationModel;
import com.jl.jlapp.eneity.EffectAdvertisementByTypeModel;
import com.jl.jlapp.mvp.activity.SearchGoodsListActivity;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;
import com.jl.jlapp.utils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class ClassifityFragment extends Fragment implements OnClickListener {
    public static int index = 0;
    List<EffectAdvertisementByTypeModel.ResultDataBean> advertisementListByType2 = new ArrayList<>();
    @BindView(R.id.classifity_advertise)
    ImageView classifityAdvertise;
    CliassifyAdapter cliassifyAdapter;
    CliassifyDetailsAdapter detailsAdapter;
    List<ClassificationModel.ResultDataBean.TwoClassificationsBean> detailsModels = new ArrayList();
    @BindView(R.id.no_two_classifity)
    TextView noTwoClassifity;
    private ProgressDialog progressDialog;
    @BindView(R.id.rlv_left)
    RecyclerView rlvLeft;
    @BindView(R.id.rlv_right)
    RecyclerView rlvRight;
    List<ClassificationModel.ResultDataBean> typeDatas;

    private void initView() {
        this.rlvLeft.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.cliassifyAdapter = new CliassifyAdapter(R.layout.item_rlv_classify_left, this.typeDatas);
        this.rlvLeft.setAdapter(this.cliassifyAdapter);
        this.cliassifyAdapter.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                ClassifityFragment.index = paramAnonymousInt;
                ClassifityFragment.this.cliassifyAdapter.notifyDataSetChanged();
                ClassifityFragment.this.rightDatas(paramAnonymousInt);
            }
        });
        rightDatas(0);
    }

    private void rightDatas(int paramInt) {
        this.detailsModels.clear();
        List<ClassificationModel.ResultDataBean.TwoClassificationsBean> localList = typeDatas.get(paramInt).getTwoClassifications();
        if (localList.size() > 0) {
            detailsModels.addAll(localList);
        }

        if (this.detailsModels.size() > 0) {
            this.noTwoClassifity.setVisibility(View.GONE);
            this.rlvRight.setVisibility(View.VISIBLE);
            setClassifityDetailAdapter();
            return;
        }
        this.noTwoClassifity.setVisibility(View.VISIBLE);
        this.rlvRight.setVisibility(View.GONE);
    }

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(getContext());
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public void getAdvertisementGoodsListByType2() {
        Net.get().getEffectAdvertisementByType(2)
                .compose(Transformer.<EffectAdvertisementByTypeModel>switchSchedulers())
                .subscribe(new CommonObserver<EffectAdvertisementByTypeModel>() {
                    @Override
                    protected void onError(String errorMsg) {
                    }

                    @Override
                    protected void onSuccess(EffectAdvertisementByTypeModel model) {
                        if (model.getCode() == 200) {
                            advertisementListByType2 = model.getResultData();
                            GlideUtils.loadUrlImage(getContext(), model.getResultData().get(0).getPicUrl(), classifityAdvertise);
                        }
                    }
                });
    }

    public void getClassificationMsg() {
        this.typeDatas = new ArrayList();
        Net.get().getClassificationMsg()
                .compose(Transformer.<ClassificationModel>switchSchedulers())
                .subscribe(new CommonObserver<ClassificationModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(ClassificationModel classificationModel) {
                        if (classificationModel.getCode() == 200) {
                            typeDatas.addAll(classificationModel.getResultData());
                            cancelProgressDialog();
                            initView();
                        }

                    }
                });
    }

    @OnClick({R.id.classifity_advertise})
    public void onClick(View paramView) {
        if (advertisementListByType2.size() == 0) return;
        int i = ((EffectAdvertisementByTypeModel.ResultDataBean) this.advertisementListByType2.get(0)).getId();
        Net.get().getAdvertisementById(i)
                .compose(Transformer.<AdvertisementByIdModel>switchSchedulers())
                .subscribe(new CommonObserver<AdvertisementByIdModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(AdvertisementByIdModel advertisementByIdModel) {

                    }
                });
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        View view = paramLayoutInflater.inflate(R.layout.search, null, false);
        ButterKnife.bind(this, view);
        buildProgressDialog();
        getClassificationMsg();
        getAdvertisementGoodsListByType2();
        return view;
    }

    public void setClassifityDetailAdapter() {
        this.rlvRight.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        this.detailsAdapter = new CliassifyDetailsAdapter(R.layout.item_rlv_right, this.detailsModels);
        this.rlvRight.setAdapter(this.detailsAdapter);
        this.detailsAdapter.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                Intent intent = new Intent(ClassifityFragment.this.getActivity(), SearchGoodsListActivity.class);
                intent.putExtra("searchMsg", "");
                intent.putExtra("classificationId", ((ClassificationModel.ResultDataBean.TwoClassificationsBean) ClassifityFragment.this.detailsModels.get(paramAnonymousInt)).getId());
                ClassifityFragment.this.startActivity(intent);
            }
        });
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/ClassifityFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */